<template>
  <div id="vas-orders" class="card col-12 px-0 mt-5">
    <template v-if="searchOption === false">
      <div class="card-header">
        <router-link class="btn btn-success ms-auto" to="/h5/new/vas/order"
          >新建</router-link
        >
        <button
          type="button"
          class="btn btn-primary float-end"
          @click.stop="showSearchOption()"
        >
          查找
        </button>
      </div>
      <vas-order-list :dataList="dataList"></vas-order-list>

      <nav id="pagination-box" class="float-end">
        <my-pagination
          name="pagination"
          :row-count="sc.rowCount"
          :page-total="sc.pageTotal"
          :page-no="sc.pageNo"
          @next-page="nextPage"
          @prev-page="prevPage"
          @direct-page="directPage"
        ></my-pagination>
      </nav>
    </template>
    <template v-else>
      <div class="card-body" v-show="searchOption">
        <form>
          <div class="row mb-2">
            <my-date-picker
              id="beginDate"
              v-model="beginDate"
              name="sc.beginDate"
              placeholder="开始日期"
            ></my-date-picker>
          </div>
          <div class="row mb-2">
            <my-date-picker
              id="endDate"
              v-model="endDate"
              name="sc.endDate"
              placeholder="截止日期"
            ></my-date-picker>
          </div>
          <div class="row mb-2">
            <input
              type="textfield"
              class="form-control mt-1"
              size="8"
              placeholder="服务单号"
              v-model.trim="orderNo"
            />
          </div>
          <div class="row mb-2">
            <select
              class="form-select mt-1"
              v-model.number="status"
              name="sc.status"
            >
              <option value="-1">所有</option>
              <option value="0">待处理</option>
              <option value="1">已处理</option>
              <option value="4">已取消</option>
            </select>
          </div>
          <div class="row mb-2">
            <button
              type="button"
              class="btn btn-primary mb-2"
              @click.stop="search()"
            >
              确定
            </button>
            <button
              type="button"
              class="btn btn-secondary btn-sm"
              @click.stop="reset()"
            >
              重置
            </button>
          </div>
        </form>
      </div>
    </template>
  </div>
</template>

<script>
import { searchVasOrders, showVasOrderStatus } from "@/api/vas.js";
import { showPayType } from "@/common/common.js";
import MyDatePicker from "@/components/my-datepicker.vue";
import MyPagination from "@/components/my-pagination_h5.vue";
import VasOrderList from "@/components/list/vas-order-list_h5.vue";

export default {
  components: {
    MyDatePicker,
    MyPagination,
    VasOrderList,
  },
  data() {
    return {
      dataList: [],

      sc: {
        rowCount: 0,
        pageNo: 1,
        pageSize: 10,
        pageTotal: 0,
      },

      beginDate: "",
      endDate: "",
      status: -1,
      orderNo: "",
      searchOption: false,
    };
  },
  mounted: function () {
    this.$store.commit("setWorkMode", "h5");
    this.search();
  },
  methods: {
    showSearchOption: function () {
      this.searchOption = true;
    },
    search: function () {
      this.searchOption = false;
      const params = {
        "sc.pageNo": this.sc.pageNo,
        "sc.pageSize": this.sc.pageSize,
        "sc.beginDate": this.beginDate,
        "sc.endDate": this.endDate,
        "sc.status": this.status,
        "sc.orderNo": this.orderNo,
      };
      searchVasOrders(params, (jsonResult) => {
        this.dataList = jsonResult.dataList;
        this.sc = jsonResult.page;
      });
    },
    showDetail: function (id) {
      this.$router.push("/h5/vas/order/" + id);
    },
    quickSearch: function (status) {
      this.status = status;
      this.search();
    },
    getStatusDesc: function (status) {
      return showVasOrderStatus(status);
    },
    getPayTypeDesc: function (payType) {
      return showPayType(payType);
    },
    reset: function () {
      this.beginDate = "";
      this.endDate = "";
      this.status = -1;
      this.sc.pageNo = 1;
      this.orderNo = "";
    },
    prevPage: function () {
      this.sc.pageNo = this.sc.pageNo - 1;
      if (this.sc.pageNo < 1) this.sc.pageNo = 1;
      this.search();
    },
    nextPage: function () {
      this.sc.pageNo = this.sc.pageNo + 1;
      this.search();
    },
    directPage: function (pageNo) {
      this.sc.pageNo = pageNo;
      this.search();
    },
  },
};
</script>